package com.hsc.www.exchangeType.topic;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Config {
    public static final String CAT_QUEUE = "catQueue";
    public static final String CAT1_QUEUE = "cat1Queue";
    public static final String CAT2_QUEUE = "cat2Queue";
    public static final String CAT_ROUTING_KEY = "cat.#";//*表示一个词,#表示零个或多个词
    public static final String CAT1_ROUTING_KEY = "cat.1";
    public static final String CAT2_ROUTING_KEY = "cat.2";
    public static final String CAT_EXCHANGE = "catExchange";


    @Bean(name = CAT_EXCHANGE)
    public TopicExchange exchange() {
        return new TopicExchange(CAT_EXCHANGE);
    }

    @Bean(name = CAT_QUEUE)
    public Queue queue() {
        return new Queue(CAT_QUEUE);
    }

    @Bean(name = CAT1_QUEUE)
    public Queue queue1() {
        return new Queue(CAT1_QUEUE);
    }

    @Bean(name = CAT2_QUEUE)
    public Queue queue2() {
        return new Queue(CAT2_QUEUE);
    }



    @Bean
    Binding bindingExchangeMessage(@Qualifier(CAT_QUEUE) Queue queue, @Qualifier(CAT_EXCHANGE) TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(CAT_ROUTING_KEY);
    }

    @Bean
    Binding bindingExchangeMessage1(@Qualifier(CAT1_QUEUE) Queue queue, @Qualifier(CAT_EXCHANGE) TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(CAT1_ROUTING_KEY);
    }

    @Bean
    Binding bindingExchangeMessage2(@Qualifier(CAT2_QUEUE) Queue queue, @Qualifier(CAT_EXCHANGE) TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(CAT2_ROUTING_KEY);
    }









}